<!--
 * @Author: libing 9852442+liu-sheng-8667@user.noreply.gitee.com
 * @Date: 2024-04-14 16:18:30
 * @LastEditors: xuezhuangzhuang xzz6996@qq.com
 * @LastEditTime: 2025-10-27 14:13:17
 * @FilePath: \crm\pages\customer\customer-pool-list.vue
 * @Description: 客户公海池列表
-->
<template>
  <view class="customer-pool-list">
    <u-navbar title="客户公海" :autoBack="true" bgColor="#FFFFFF"> </u-navbar>
    <!-- <RenDropdownFilter :filterData="filterData" :defaultIndex="defaultIndex" /> -->
    <div
      style="display: flex; justify-content: space-between; margin-top: 20px"
    >
      <!-- 请输入搜索内容 -->
      <view class="search">
        <u-search
          placeholder="请输入客户名称"
          v-model="name"
          bgColor="#FFFFFF"
          borderColor="#F8CCCC"
          height="74rpx"
          placeholderColor="#C1C5C9"
          :showAction="false"
          @change="upper"
        />
      </view>
      <view class="search">
        <u-search
          placeholder="请输入手机号"
          v-model="phone"
          bgColor="#FFFFFF"
          borderColor="#F8CCCC"
          height="74rpx"
          placeholderColor="#C1C5C9"
          :showAction="false"
          @change="upper"
        />
      </view>
    </div>
    <!-- 请输入搜索内容 -->
    <view class="nav-wrap">
      <u-tabs :list="navList" @change="changeHandle"></u-tabs>
    </view>
    <scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="lower">
      <!-- 无限滚动列表 -->
      <view v-for="(item, index) in list" :key="index" class="wrap">
        <CompanyItem
          isActive
          :item="item"
          :customerTypesObj="customerTypesObj"
        />
        <u-button
          type="primary"
          color="#DC2626"
          text="抢入私海"
          @click="onAdd(index, 0)"
          v-if="defaltParams.highSeas == -1"
          >抢入私海</u-button
        >
        <u-button
          type="primary"
          color="#DC2626"
          text="抢入私海"
          @click="onAdd(index, 1)"
          v-if="defaltParams.highSeas == 1"
          >抢入私海</u-button
        ></view
      >
      <u-loadmore :status="status" />
    </scroll-view>
  </view>
</template>
<script>
import CustomerItem from "./conponents/customer-item.vue";
import listPageMixins from "./mixins/scroll-list";
import RenDropdownFilter from "@/components/ren-dropdown-filter/ren-dropdown-filter.vue";
import { getCompanyList, getCustomerSeasEdit } from "@/apis/customer/index";
import CompanyItem from "./conponents/company-item.vue";
import { getUserInfo, setUserInfo } from "@/config/storage";
import asyncSelect from "./mixins/async-select";
import { getUserInfo as reqUserInfo } from "@/apis/user";
export default {
  name: "my-customer",
  components: {
    CustomerItem,
    RenDropdownFilter,
    CompanyItem,
  },
  mixins: [listPageMixins, asyncSelect],
  data() {
    return {
      userInfo: {},
      queryAPI: getCompanyList,
      filterData: [[{ text: "全部", value: "" }]],
      defaultIndex: [0, 0],
      navList: [
        {
          name: "公司公海",
        },
        {
          name: "部门公海",
        },
      ],
      phone: "",
      name: "",
    };
  },
  onShow() {
    this.userInfo = getUserInfo();
    Object.assign(this.defaltParams, {
      highSeas: -1,
      sysuserid: this.userInfo.userId,
    });
    this.getList();
  },
  methods: {
    onAdd(index, index1) {
      this.userInfo = getUserInfo();
      let obj = {};
      let id = this.list[index].id;
      if (index1 === 0) {
        obj = {
          id,
          highSeas: 0,
          sysuserid: this.userInfo.userId,
        };
      } else {
        obj = {
          id,
          highSeas: 1,
          deptId: this.userInfo.deptId,
        };
      }
      getCustomerSeasEdit(obj);
      uni.showToast({
        title: "操作成功",
        icon: "none",
        duration: 500,
      });
      this.list = [];
      setTimeout(() => {
        this.getList();
      }, 200);
    },
    async changeHandle(val) {
      const index = val.index;
      if (!this.userInfo?.deptId || !this.userInfo?.userId) {
        const res = await reqUserInfo();
        setUserInfo(res.sysUser);
        this.userInfo = res.sysUser;
      }
      let body = {};
      if (index == 1) {
        this.defaltParams = {
          highSeas: 1,
          deptId: this.userInfo.deptId,
        };
      }
      if (index === 0) {
        this.defaltParams = {
          highSeas: -1,
          sysuserid: this.userInfo.userId,
        };
      }
      this.upper();
    },
    dateChange(d) {
      uni.showToast({
        icon: "none",
        title: d,
      });
    },
  },
};
</script>
<style scoped lang="scss">
.scroll-Y {
  height: calc(100vh - 350rpx);
}
.nav-wrap {
  // padding-top: 100rpx;
}
.customer-pool-list {
  height: 100vh;
  padding: 0 18rpx;
  background: #f2f4f5;
}
.wrap {
  background: #ffffff;
  border-radius: 16rpx;
  padding: 24rpx 0;
  margin-top: 20rpx;
}
</style>
